//
//  MineHeaderInfoView.swift
//  ManBetX
//
//  Created by Cocoa on 2020/4/14.
//  Copyright © 2020 Fullen. All rights reserved.
//

/**
 * 存款、取款、转账、回收 所在的View
 */
import UIKit

typealias buttonClickBlock = () -> Void

class MineHeaderInfoView: UIView {

    var depositClickBlock:buttonClickBlock?
    var withdrawalClickBlock:buttonClickBlock?
    var transferClickBlock:buttonClickBlock?
    var recycleClickBlock:buttonClickBlock?
    
    lazy var depositButton = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: 32, height: 50))//存款
    lazy var withdrawalButton = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: 32, height: 50))//取款
    lazy var transferButton = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: 32, height: 50))//转账
    lazy var recycleButton = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: 32, height: 50))//回收
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
        configureButton()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func configureButton() {
        self.depositButton.setImage(UIImage.init(named: "mine_icon_deposit"), for: .normal)
        self.depositButton.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        self.depositButton.setTitleColor(UIColor.init("333333"), for: .normal)
        self.depositButton.setTitle("存款", for: .normal)
        self.depositButton.addTarget(self, action: #selector(depositButtonClick), for: .touchUpInside)
        self.depositButton.imagePosition(style: UIButton.ButtonImagePosition.top, spacing: 6)
        self.addSubview(self.depositButton)
        
        self.withdrawalButton.setImage(UIImage.init(named: "mine_icon_withdrawal"), for: .normal)
        self.withdrawalButton.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        self.withdrawalButton.setTitleColor(UIColor.init("333333"), for: .normal)
        self.withdrawalButton.setTitle("取款", for: .normal)
        self.withdrawalButton.addTarget(self, action: #selector(withdrawalButtonClick), for: .touchUpInside)
        self.withdrawalButton.imagePosition(style: UIButton.ButtonImagePosition.top, spacing: 6)
        self.addSubview(self.withdrawalButton)
        
        self.transferButton.setImage(UIImage.init(named: "mine_icon_transfer"), for: .normal)
        self.transferButton.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        self.transferButton.setTitleColor(UIColor.init("333333"), for: .normal)
        self.transferButton.setTitle("转账", for: .normal)
        self.transferButton.addTarget(self, action: #selector(transferButtonClick), for: .touchUpInside)
        self.transferButton.imagePosition(style: UIButton.ButtonImagePosition.top, spacing: 6)
        self.addSubview(self.transferButton)
        
        self.recycleButton.setImage(UIImage.init(named: "mine_icon_recycle"), for: .normal)
        self.recycleButton.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        self.recycleButton.setTitleColor(UIColor.init("333333"), for: .normal)
        self.recycleButton.setTitle("回收", for: .normal)
        self.recycleButton.addTarget(self, action: #selector(recycleButtonClick), for: .touchUpInside)
        self.recycleButton.imagePosition(style: UIButton.ButtonImagePosition.top, spacing: 6)
        self.addSubview(self.recycleButton)
       
        let buttonWidth: CGFloat = 32
        let buttonHeight: CGFloat = 50
        let leftMargin: CGFloat = 35
        let numSpace: CGFloat = (self.bounds.width - leftMargin * 2 - buttonWidth * 4)/3
        
        self.depositButton.snp.makeConstraints { (make) in
            make.left.equalTo(35.0)
            make.centerY.equalToSuperview().offset(5)
            make.width.equalTo(buttonWidth)
            make.height.equalTo(buttonHeight)
        }
        self.withdrawalButton.snp.makeConstraints { (make) in
            make.left.equalTo(self.depositButton.snp.right).offset(numSpace)
            make.centerY.equalToSuperview().offset(5)
            make.width.equalTo(buttonWidth)
            make.height.equalTo(buttonHeight)
        }
        self.transferButton.snp.makeConstraints { (make) in
            make.right.equalTo(self.recycleButton.snp.left).offset(-numSpace)
            make.centerY.equalToSuperview().offset(5)
            make.width.equalTo(buttonWidth)
            make.height.equalTo(buttonHeight)
        }
        self.recycleButton.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-leftMargin)
            make.centerY.equalToSuperview().offset(5)
            make.width.equalTo(buttonWidth)
            make.height.equalTo(buttonHeight)
        }
    }
    
    @objc func depositButtonClick(){
        print("depositButtonClick")
        
        if self.depositClickBlock != nil {
            self.depositClickBlock!()
        }
    }
    @objc func withdrawalButtonClick(){
        print("depositButtonClick")
        if self.withdrawalClickBlock != nil {
            self.withdrawalClickBlock!()
        }
    }
    @objc func transferButtonClick(){
        print("depositButtonClick")
        if self.transferClickBlock != nil {
            self.transferClickBlock!()
        }
    }
    @objc func recycleButtonClick(){
        print("depositButtonClick")
        if self.recycleClickBlock != nil {
            self.recycleClickBlock!()
        }
    }
}
